package com.zxj

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.expressions.{Add, Literal}
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule

case class MyPushDown(spark: SparkSession) extends Rule[LogicalPlan] {
  logWarning("zxj.MyPushDown")

  def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions  {
    case Add(left, right, failOnError)
      if left.isInstanceOf[Literal] && left.asInstanceOf[Literal].value.asInstanceOf[Int] == 0
    => right
    case Add(left, right, failOnError)
      if right.isInstanceOf[Literal] && right.asInstanceOf[Literal].value.asInstanceOf[Int] == 0
    => left
  }
}
